// 分类API - 使用后端真实请求
import { post } from '@/utils/request'

export default {
	// 获取完整的分类层级数据
	async getCategoryTree() {
		const res = await post('/api/categorys/getCategoryTree', {})
		return res.data
	},

	// 获取热门分类
	async getHotCategories() {
		const categoryTree = await this.getCategoryTree()
		const hotCategories = []

		categoryTree.forEach(category => {
			if (category.hot) {
				hotCategories.push({
					id: category.id,
					name: category.name,
					title: category.title,
					text: category.text,
					icon: category.icon,
					type: category.type,
					hot: true
				})
			}
		})

		return hotCategories
	},

	// 获取推荐分类
	async getRecommendedCategories() {
		const categoryTree = await this.getCategoryTree()
		const recommendedCategories = []

		categoryTree.forEach(category => {
			if (category.recommend) {
				recommendedCategories.push({
					id: category.id,
					name: category.name,
					title: category.title,
					text: category.text,
					icon: category.icon,
					type: category.type,
					recommend: true,
					desc: category.text
				})
			}
		})

		return recommendedCategories
	},

	// 保留原有方法兼容性
	async sortListData() {
		const categories = await this.getHotCategories()
		return categories.map(item => ({
			id: item.id,
			name: item.name,
			img: item.icon
		}))
	}
};